<?php

namespace App\Logging;

use GuzzleHttp\Client;

class WechatLogger extends CreateCustomLogger
{
    private string $url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send';

    protected function write($message, array $context = [])
    {
        $accessToken = data_get($this->config, 'accessToken');
        if ($accessToken) {
            $url = $this->url . '?key=' . $accessToken;
            $client = new Client();
            $client->post($url, [
                'json' => [
                    'msgtype' => 'text',
                    'text'    => [
                        'content' => "【edu】\n" . $message,
                    ],
                ],
            ]);
        }
    }
}
